$(function() {
  var search=decodeURI(window.location.search.substr(1)),
  callerInfo=matchQueryString(search,'caller'),
  companyInfo=matchQueryString(search,'authData'),
  userId=matchQueryString(search,'ext_terminalCode'),
  isadmin=matchQueryString(search,'isadmin'),
  isAdmin=(isadmin===1||isadmin==='1')?true:false,//不设置isadmin参数默认为非管理员
  code=matchQueryString(search,'code'),
  index=matchQueryString(search,'index'),
  isLoadContacts=matchQueryString(search,'isLoadContacts')||'0',
  showAlipay=matchQueryString(search,'showAlipay'),
  isShowAlipay=(showAlipay===-1||showAlipay==='-1'||showAlipay==='0'||showAlipay===0)?true:false,//设置是否显示支付宝支付
  showUnionAccount=matchQueryString(search,'showUnionAccount'),
  isShowUnionAccount=(showUnionAccount===1||showUnionAccount==='1'||showUnionAccount==='')?true:false,//不设置showUnionAccount参数默认显示账户合并页面
  contacts=localCache.getSessionItem('contacts'),  
  callerObject=getJSONParsedObject(callerInfo,'主叫信息参数格式错误'),
  companyObject=getJSONParsedObject(companyInfo,'组织信息参数格式错误');
  var called=getJSONParsedObject(contacts,'被叫信息参数格式错误'); 
  localCache.load(true);//加载基本缓存参数  
  if(code==='0000'||code==='0017'||code==='0019'){//校验通过\余额不足\管理员登录没有配置充值相关信息
      //根据index值路由页面，默认进入欢迎页面
      index=(index==='')?0:Number(index);
      //调用接口缓存用户数据
      localCache.setSessionItems({
        account_identifer:matchQueryString(search,'app_key'),
        timestamp:matchQueryString(search,'timestamp'),
        sign:matchQueryString(search,'sign'),
        periphery_code:matchQueryString(search,'periphery_code'),
        periphery_account:matchQueryString(search,'cust_account'),
        caller:callerObject.telephone,
        callerName:callerObject.name,
        account_identify:matchQueryString(search,'cust_account'),
        companyName:companyObject.ext_orgName,
        userId:(userId==='')?callerObject.telephone:userId,
        isAdmin:isAdmin,
        index:matchQueryString(search,'index'),
        isLoadContacts:isLoadContacts,
        supportUap:matchQueryString(search,'supportUap')||'0',
        isShowAlipay:isShowAlipay,
        isShowUnionAccount:isShowUnionAccount
      });
      if(code==='0017')//余额不足
    	  index=isAdmin?6:7;
      if(code==='0019'){//未设置充值信息     
          new UserPrompt(matchQueryString(search,'describe'),function(){
              router(index);        
          });
          return;
      }else{
          if(isAdmin){//登录人员为管理员时，缓存组织编码、产品编码、区域编码，卡充值时使用
              localCache.setSessionItems({
                company_code:matchQueryString(search,'company_code'),
                product_code:matchQueryString(search,'product_code'),
                region_code:matchQueryString(search,'region_code')
              });
          }
      }
      if(index===0&&meetCache.hasMeetStorage())//存在通话记录
    	  index=10;
      if(index===11){
          router(index,window.location.search+'&isAuth=1');//直接跳转到两方拨号页面
        }else if(index===12){
		   var dataObject={
   			data:[{
   				name:callerObject.name,
   				telephone:callerObject.telephone,
   				type:'main'
   			}]     		
		   };
		    Array.prototype.push.apply(dataObject.data,called);
          router(index,window.location.search+'&data='+JSON.stringify(dataObject));//直接跳转到两方拨号页面
        }else
          router(index);     
  }else if(code==='0015'){//账户不存在，需要进入注册页面
	router(8);
  }else{//其他参数异常
    new UserPrompt(matchQueryString(search,'describe'));
  }
 }
)



